<template>
  <div class="swiperContent">
    <swiper
      class="swiper"
      :options="swiperOption"
      ref="mySwiper"
      @mouseenter.native="swiperShow = !swiperShow"
    >
      <!-- slides -->
      <swiper-slide v-for="item of dataImg" :key="item.id">
        <img :src="item.src" alt srcset />
      </swiper-slide> 
      <!-- Optional controls -->
      <div class="swiper-pagination" slot="pagination"></div>
    </swiper>
    <div class="swiper-button-prev"></div>
    <!--左箭头。如果放置在swiper-container外面，需要自定义样式。-->
    <div class="swiper-button-next"></div>
    <!--右箭头。如果放置在swiper-container外面，需要自定义样式。--> 
  </div>
</template>
<script>
export default {
  name: "MainSwiper",
  data() {
    return {
      dataImg:[
        {
          src:"/static/image/banner.jpg",
          id:"001"
        },
         {
          src:"/static/image/banner2.jpg",
          id:"002"
        },
         {
          src:"/static/image/banner3.jpg",
          id:"003"
        }
      ],
      swiperShow: false,
      swiperOption: {
        autoplay: true,
        pagination: {
          el: ".swiper-pagination",
          clickable: true
        },
        navigation: {
          nextEl: ".swiper-button-next",
          prevEl: ".swiper-button-prev"
        }
      }
    };
  },
  computed: {
    swiper() {
      console.log(this.$refs.mySwiper.swiper);
      return this.$refs.mySwiper.swiper;
    }
  },
  mounted() {
    // 然后你就可以使用当前上下文内的swiper对象去做你想做的事了
    console.log("this is current swiper instance object", this.swiper);
  }
};
</script>
<style scoped>
.swiperContent {
  position: relative;
}
.swiper-slide img {
  width: 100%;
  height: 420px;
}
.swiper {
  position: relative;
}
.swiper >>> .swiper-pagination-bullet {
  width: 30px;
  border-radius: 0;
  height: 2px;
}
.swiper >>> .swiper-pagination-bullet-active {
  background: white;
}
.swiper-button-prev,
.swiper-button-next {
  transition: all 0.3s;
}
</style>